using System;
using UnityEngine;

public class SupportTools
{
	[Flags]
	public enum AxisIgnore
	{
		IgnoreX = 0x1,
		IgnoreY = 0x2,
		IgnoreZ = 0x4
	}

	public static GameObject AddChild(Transform parent, Transform child)
	{
		RectTransform component = child.GetComponent<RectTransform>();
		child.SetParent(parent);
		if ((bool)component)
		{
			component.anchoredPosition = Vector2.zero;
		}
		else
		{
			child.localPosition = Vector3.zero;
		}
		child.localRotation = Quaternion.identity;
		child.localScale = Vector3.one;
		return child.gameObject;
	}

	public static GameObject AddChild(GameObject parent, GameObject child)
	{
		GameObject gameObject = UnityEngine.Object.Instantiate(child);
		return AddChild(parent.transform, gameObject.transform);
	}

	public static T AddChild<T>(GameObject parent, GameObject child) where T : Component
	{
		return AddChild(parent, child).GetComponent<T>();
	}

	public static T AddChild<T>(GameObject parent, string path) where T : Component
	{
		GameObject gameObject = AddChild(parent, (GameObject)Resources.Load(path));
		return gameObject.GetComponent<T>();
	}

	public static T AddChild<T>(GameObject parent) where T : Component
	{
		GameObject gameObject = new GameObject();
		T result = gameObject.AddComponent<T>();
		AddChild(parent.transform, gameObject.transform);
		return result;
	}

	public static void SetPosition(GameObject o, Vector3 position, AxisIgnore ignore, bool useRigibody = false)
	{
		Vector3 position2 = o.transform.position;
		if ((ignore & AxisIgnore.IgnoreX) == (AxisIgnore)0)
		{
			position2.x = position.x;
		}
		if ((ignore & AxisIgnore.IgnoreY) == (AxisIgnore)0)
		{
			position2.y = position.y;
		}
		if ((ignore & AxisIgnore.IgnoreZ) == (AxisIgnore)0)
		{
			position2.z = position.z;
		}
		o.transform.position = position2;
	}

	public static bool OpenRateAppDialog()
	{
		int num;
		if (!PlayerPrefs.HasKey("RateInterval"))
		{
			num = 10;
			PlayerPrefs.SetInt("RateInterval", num);
		}
		else
		{
			num = PlayerPrefs.GetInt("RateInterval");
		}
		if (num == 40)
		{
			return false;
		}
		int index = ConstantData.LevelDatas.GetIndex(LevelDataIndex.CurrentLevel.FileName);
		if (index % num == 0)
		{
			int num2 = PlayerPrefs.HasKey("RateProgress") ? PlayerPrefs.GetInt("RateProgress") : 0;
			if (num2 < index)
			{
				UIADViewWnd.Show(UIADViewWnd.ADViewType.Rate);
				return true;
			}
		}
		return false;
	}

	public static Vector3 GetPointerDirWithTargetBallAndTargetPocket(PoolBall targetBall, PocketTrigger targetPocket)
	{
		return GetHitPoint(targetBall, targetPocket) - Pools.CueBall.GetPosition();
	}

	public static Vector3 GetPointerDirWithTargetBallAndTargetPocketUI(PoolBall targetBall, PocketTrigger targetPocket)
	{
		return MathTools.World2UI(GetHitPoint(targetBall, targetPocket)) - MathTools.World2UI(Pools.CueBall.GetPosition());
	}

	public static Vector3 GetHitPoint(PoolBall ball, PocketTrigger trigger)
	{
		Vector3 vector = ball.transform.position - trigger.GetBestPoint(ball.transform.position);
		return ball.transform.position + vector.normalized * ball.GetRadius() * 2f;
	}
}
